//
//  RecInfo.m
//  Lazy
//
//  Created by yoky on 14-6-23.
//  Copyright (c) 2014年 Echo. All rights reserved.
//

#import "RecInfo.h"

@implementation RecInfo
@synthesize day, startTime, endTime, seconds, param1, param2,param3;
- (void)encodeWithCoder:(NSCoder *)encoder {
    [encoder encodeObject:day forKey:@"day"];
	[encoder encodeObject:startTime forKey:@"startTime"];
    [encoder encodeObject:endTime forKey:@"endTime"];
    [encoder encodeObject:seconds forKey:@"seconds"];
    [encoder encodeObject:param1 forKey:@"param1"];
    [encoder encodeObject:param2 forKey:@"param2"];
    [encoder encodeObject:param3 forKey:@"param3"];
}

- (id)initWithCoder:(NSCoder *)decoder{
	self=[super init];
    self.day = [decoder decodeObjectForKey:@"day"];
    self.startTime = [decoder decodeObjectForKey:@"startTime"];
    self.endTime = [decoder decodeObjectForKey:@"endTime"];
    self.seconds = [decoder decodeObjectForKey:@"seconds"];
    self.param1 = [decoder decodeObjectForKey:@"param1"];
    self.param2 = [decoder decodeObjectForKey:@"param2"];
    self.param3 = [decoder decodeObjectForKey:@"param3"];
	return self;
}
+(NSString*)storePathWithFileName:(NSString*)fileName {
    if ([fileName length]==0) {
        return nil;
    }
    NSString *path=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    if ( ! [[NSFileManager defaultManager] fileExistsAtPath:path]) {
		[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
	}
	NSString *filePath=[path stringByAppendingPathComponent:fileName];
	return filePath;
}
+(void)archiverObject:(id)object path:(NSString*)path key:(NSString*)key{
    NSMutableData *data = [[NSMutableData alloc] init];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    [archiver encodeObject:object forKey:key];
    [archiver finishEncoding];
    [data writeToFile:path atomically:YES];
}
+(id)unarchiverObjectFromPath:(NSString*)path key:(NSString*)key{
    NSData *data = [[NSMutableData alloc]
                    initWithContentsOfFile:path];
    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc]
                                     initForReadingWithData:data];
    id object = [unarchiver decodeObjectForKey:key];
    [unarchiver finishDecoding];
    return object;
}
@end
